﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraGrid.Views.Grid;
using System.Reflection;
using System.ComponentModel;

namespace SchoolManagementSystem.Controls
{
     class SetDescriptionForColumn
    {
         public static void SetDescription(GridView gridView1, object _model)
         {
             PropertyInfo[] propertyInfos;
             propertyInfos = _model.GetType().GetProperties(); ;

             foreach (PropertyInfo proInfo in propertyInfos)
             {
                 AttributeCollection attributes = TypeDescriptor.GetProperties(_model.GetType())[proInfo.Name].Attributes;

                 DescriptionAttribute myAttribute =
                    (DescriptionAttribute)attributes[typeof(DescriptionAttribute)];
                 if (String.IsNullOrEmpty(myAttribute.Description))
                 {
                     gridView1.Columns[proInfo.Name].Visible = false;
                 }
                 else
                 {
                     gridView1.Columns[proInfo.Name].Caption = myAttribute.Description;
                     gridView1.Columns[proInfo.Name].OptionsColumn.AllowEdit = false;
                 }
             }
         }
    }
}
